<?php
$config = [
    'name' => 'zuxianzhi',
    'vendorPath' => __DIR__ . '/../../vendor',
    'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
    'sourceLanguage' => 'en-US',
    'language' => 'zh-CN',
    'bootstrap' => ['log','queue','queue2','queue3','debug'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm' => '@vendor/npm-asset',
    ],

    //'on beforeRequest' =>['common\SystemEvent','beforeRequest'],
    'components' => [
        'authManager' => [
            'class' => yii\rbac\DbManager::class,
            'itemTable' => '{{%rbac_auth_item}}',
            'itemChildTable' => '{{%rbac_auth_item_child}}',
            'assignmentTable' => '{{%rbac_auth_assignment}}',
            'ruleTable' => '{{%rbac_auth_rule}}'
        ],
//        'devicedetect' => [
//            'class' => 'alexandernst\devicedetect\DeviceDetect'
//        ],
        'cache' => [
            'class' => 'yii\redis\Cache',
            'keyPrefix' => 'yiiCache:',
        ],

        'commandBus' => [
            'class' => trntv\bus\CommandBus::class,
            'middlewares' => [
                [
                    'class' => trntv\bus\middlewares\BackgroundCommandMiddleware::class,
                    'backgroundHandlerPath' => '@console/yii',
                    'backgroundHandlerRoute' => 'command-bus/handle',
                ]
            ]
        ],
        'formatter' => [
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'CNY',
            'nullDisplay' => '',

        ],
        'glide' => [
            'class' => trntv\glide\components\Glide::class,
            'sourcePath' => '@storage/web/source',
            'cachePath' => '@storage/cache',
            'urlManager' => 'urlManagerStorage',
            'maxImageSize' => env('GLIDE_MAX_IMAGE_SIZE'),
            'signKey' => env('GLIDE_SIGN_KEY')
        ],



        'db' => [
            'class' => yii\db\Connection::class,
            'dsn' => env('DB_DSN'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'tablePrefix' => env('DB_TABLE_PREFIX'),
            'charset' => env('DB_CHARSET', 'utf8mb4'),
            'enableSchemaCache' => YII_ENV_PROD,
        ],

        'db2' => [
            'class' => yii\db\Connection::class,
            'dsn' => env('DB_DSN2'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'tablePrefix' => env('DB_TABLE_PREFIX'),
            'charset' => env('DB_CHARSET', 'utf8mb4'),
            'enableSchemaCache' => YII_ENV_PROD,
        ],

        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'redis',
            'port' => 6379,
        ],
        'session' => [
            'class' => 'yii\redis\Session',
            'timeout' => 6000,
        ],

        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                'db' => [
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['error', 'warning'],
                    'except' => ['yii\web\HttpException:*', 'yii\i18n\I18N\*'],
                    'prefix' => function () {
                        $url = !Yii::$app->request->isConsoleRequest ? Yii::$app->request->getUrl() : null;
                        return sprintf('[%s][%s]', Yii::$app->id, $url);
                    },
                    'categories' => [
                        'test',
                    ],
                    //'logVars' => [],
                    'logTable' => '{{%system_log}}'
                ],
                'db2' => [
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['profile'],
                    'except' => ['yii\web\HttpException:*', 'yii\i18n\I18N\*'],
//                    'prefix' => function () {
//                        $url = !Yii::$app->request->isConsoleRequest ? Yii::$app->request->getUrl() : null;
//
//                        $user = Yii::$app->has('user', true) ? Yii::$app->get('user') : null;
//                        $userID = $user ? $user->getId(false) : '-';
//
//                        return sprintf('[%s][%s]', Yii::$app->id, $url)."[$userID]";
//                    },
                    'categories' => [
                        'test',
                    ],
                    //'logVars' => [],
                    'logTable' => '{{%system_log}}'
                ],
                'es' => [
                    'class' => 'yii\elasticsearch\ElasticsearchTarget',
                    'except' => ['yii\web\HttpException:*', 'yii\i18n\I18N\*'],
                    'levels' => ['error', 'warning'],
//                    'index' => 'yii-log',
//                    'type' => 'console',
//                    'extraFields' => [
//                        'ip' => function ($app) {
//                            return $app->request->getUserIP();
//                        }
//                    ]
                ],
            ],
        ],

        'i18n' => [
            'translations' => [
//                '*' => [
//                    'class' => yii\i18n\PhpMessageSource::class,
//                    'basePath' => '@common/messages',
//                    'fileMap' => [
//                        'common' => 'common.php',
//                        'backend' => 'backend.php',
//                        'frontend' => 'frontend.php',
//                    ],
//                    'on missingTranslation' => [backend\modules\translation\Module::class, 'missingTranslation']
//                ],
                // Uncomment this code to use DbMessageSource
                '*'=> [
                    'class' => yii\i18n\DbMessageSource::class,
                    'sourceMessageTable'=>'{{%i18n_source_message}}',
                    'messageTable'=>'{{%i18n_message}}',
                    'enableCaching' => YII_ENV_DEV,
                   // 'cachingDuration' => 3600,
                    'on missingTranslation' => [backend\modules\translation\Module::class, 'missingTranslation']
                ],

            ],
        ],

        'fileStorage' => [
            'class' => trntv\filekit\Storage::class,
            'baseUrl' => '@storageUrl/source',
            'filesystem' => [
                'class' => common\components\filesystem\LocalFlysystemBuilder::class,
                'path' => '@storage/web/source'
            ],
            'as log' => [
                'class' => common\behaviors\FileStorageLogBehavior::class,
                'component' => 'fileStorage'
            ]
        ],

        'keyStorage' => [
            'class' => common\components\keyStorage\KeyStorage::class
        ],

        'urlManagerBackend' => \yii\helpers\ArrayHelper::merge(
            [
                'hostInfo' => env('BACKEND_HOST_INFO'),
                'baseUrl' => env('BACKEND_BASE_URL'),
            ],
            require(Yii::getAlias('@backend/config/_urlManager.php'))
        ),
        'urlManagerFrontend' => \yii\helpers\ArrayHelper::merge(
            [
                'hostInfo' => env('FRONTEND_HOST_INFO'),
                'baseUrl' => env('FRONTEND_BASE_URL'),
            ],
            require(Yii::getAlias('@frontend/config/_urlManager.php'))
        ),
        'urlManagerStorage' => \yii\helpers\ArrayHelper::merge(
            [
                'hostInfo' => env('STORAGE_HOST_INFO'),
                'baseUrl' => env('STORAGE_BASE_URL'),
            ],
            require(Yii::getAlias('@storage/config/_urlManager.php'))
        ),

        'queue' => [
            'class' => 'yii\queue\redis\Queue',
            'redis' => 'redis', // 连接组件或它的配置
            'channel' => 'queue', // Queue channel key
            'as log' => 'yii\queue\LogBehavior',// 日志
            'as jobMonitor' => \zhuravljov\yii\queue\monitor\JobMonitor::class,
            'as workerMonitor' => \zhuravljov\yii\queue\monitor\WorkerMonitor::class,
//            'as log' => \yii\queue\LogBehavior::class,
//            'as quuemanager' => \ignatenkovnikita\queuemanager\behaviors\QueueManagerBehavior::class
        ],
        'queue2' => [
            'class' => \yii\queue\amqp\Queue::class,
            'host' => 'localhost',
            'port' => 5672,
            'user' => 'zuxianzhi',
            'password' => '123123',
            'queueName' => 'queue',
            'as log' => 'yii\queue\LogBehavior',// 日志
            'as jobMonitor' => \zhuravljov\yii\queue\monitor\JobMonitor::class,
            'as workerMonitor' => \zhuravljov\yii\queue\monitor\WorkerMonitor::class,
        ],

        'queue3' => [
            'class' => \yii\queue\amqp_interop\Queue::class,
            'port' => 5672,
            'user' => 'zuxianzhi',
            'password' => '123123',
            'queueName' => 'queue2',
            'ttr'=>60,
            'attempts'=>1,//必须大于0
            'driver' => yii\queue\amqp_interop\Queue::ENQUEUE_AMQP_LIB,
            'as log' => 'yii\queue\LogBehavior',// 日志
            'as jobMonitor' => \zhuravljov\yii\queue\monitor\JobMonitor::class,
            'as workerMonitor' => \zhuravljov\yii\queue\monitor\WorkerMonitor::class,
//            // or
//            'dsn' => 'amqp://guest:guest@localhost:5672/%2F',
//
//            // or, same as above
//            'dsn' => 'amqp:',
        ],

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtpdm.aliyun.com',
                'username' => 'no-reply@support.kuibu.co',
                'password' => 'no-reply@support.kuibu.co',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            'viewPath' => '@common/mail',
            'useFileTransport' => false,
        ],
        
        'mailer1' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtpdm.aliyun.com',
                'username' => 'no-reply2@support.kuibu.co',
                'password' => 'no-reply2@support.kuibu.co',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            'viewPath' => '@common/mail',
            'useFileTransport' => false,
        ],


         'mailer2' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.qq.com',
                'username' => 'hi.sunbo@qq.com',
                'password' => 'lighdncdyywlbiff',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            'viewPath' => '@common/mail',
            'useFileTransport' => false,
        ],

        

        'elasticsearch' => [
            'class' => 'yii\elasticsearch\Connection',
            'autodetectCluster'=>false,
            'nodes' => [
                ['http_address' =>  env('ES')]
            ]
,
            'dslVersion' => 7, 
            
        ],
    ],

    'container' => [
        'singletons' => [
            \zhuravljov\yii\queue\monitor\Env::class => [
                'cache' => 'cache',
                'db' => 'db',
                'pushTableName'   => '{{%queue_push}}',
                'execTableName'   => '{{%queue_exec}}',
                'workerTableName' => '{{%queue_worker}}',
            ],
        ],
    ],
    'params' => [
        'adminEmail' => env('ADMIN_EMAIL'),
        'robotEmail' => env('ROBOT_EMAIL'),
        'availableLocales' => [
//            'ru-RU' => 'Русский (РФ)',
//            'uk-UA' => 'Українська (Україна)',
//            'es' => 'Español',
//            'fr' => 'Français',
//            'vi' => 'Tiếng Việt',
            'zh-CN' => '简体中文',
            'en-US' => 'English (US)',
          //  'pl-PL' => 'Polski (PL)',
        ],

        
    ],

    'modules' => [

        'dynagrid'=> [
            'class'=>'\kartik\dynagrid\Module',
            // other module settings
        ],
        'gridview'=> [
            'class'=>'\kartik\grid\Module',
            // other module settings
        ],
        'monitor' => [
            'class' => \zhuravljov\yii\queue\monitor\Module::class,
        ],
//        'queuemanager' => [
//            'class' => \ignatenkovnikita\queuemanager\QueueManager::class
//        ],
        'datecontrol' =>  [
            'class' => 'kartik\datecontrol\Module',

            // format settings for displaying each date attribute
            'displaySettings' => [
                'date' => 'Y-m-d',
                'time' => 'H:i:s A',
                'datetime' => 'Y-m-d H:i:s A',
            ],

            // format settings for saving each date attribute
            'saveSettings' => [
                'date' => 'Y-m-d',
                'time' => 'H:i:s',
                'datetime' => 'Y-m-d H:i:s',
            ],



            // automatically use kartik\widgets for each of the above formats
            'autoWidget' => true,

        ],
        'debug' => [
            'class' => \yii\debug\Module::class,
            'panels' => [
                'queue' => \yii\queue\debug\Panel::class,
                'elasticsearch' => [
                    'class' => 'yii\\elasticsearch\\DebugPanel',
                ],
            ],
        ],
    ],
];

if (YII_ENV_PROD) {
    $config['components']['log']['targets']['email'] = [
        'class' => yii\log\EmailTarget::class,
        'except' => ['yii\web\HttpException:*'],
        'levels' => ['error', 'warning'],
        'message' => ['from' => env('ROBOT_EMAIL'), 'to' => env('ADMIN_EMAIL')]
    ];
}

if (YII_ENV_DEV) {
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => yii\gii\Module::class
    ];

    $config['components']['cache'] = [
        'class' => yii\caching\DummyCache::class
    ];
    $config['components']['mailer']['transport'] = [
        'class' => 'Swift_SmtpTransport',
        'host' => env('SMTP_HOST'),
        'port' => env('SMTP_PORT'),
    ];
}

return $config;
